<?php
require_once('header.php');
include("adodb5/adodb-exceptions.inc.php");
include('adodb5/adodb.inc.php');

$strDsn = 'mssql://influenza:inf123456@10.1.251.14';
$strHtmlOutput = '';

$cnn = ADONewConnection($strDsn);
$cnn->SetFetchMode(ADODB_FETCH_ASSOC);

$intEntidad = $_REQUEST['intEntidad'];

if($cnn)
{
//
	$strSql = "SELECT	id_delegacion, 
						descripcion FROM Catalogos.dbo.delegaciones 
						ORDER BY descripcion ASC";
	
	$rs = $cnn->Execute($strSql);
	
	if($rs)
	{
	//
		$intNoRows = $rs->RecordCount();
		
		if($intNoRows > 0)
		{
		//
			$strHtmlOutput .=	'<select name="cboDelegacion" id="cboDelegacion" onchange="javascript:updateControl(\'divUsmiNameList\', \'cboUsmiNameFill.php\', {intEntidad: $(\'cboDelegacion\').options[$(\'cboDelegacion\').selectedIndex].value, intSector: $(\'cboSector\').options[$(\'cboSector\').selectedIndex].value });">';

			while(!$rs->EOF)
			{
			//
				$rs->FetchInto($arrCurrentRow);
				$strIdEntidad = $arrCurrentRow['id_delegacion'];
				$strNombre = htmlentities($arrCurrentRow['descripcion']);
				if ($strIdEntidad == $intEntidad)
					{	$sel = "selected=\"selected\"";	}
				else
					{	$sel = "";	}
				$strHtmlOutput .=	"<option value=\"$strIdEntidad\" $sel>$strNombre</option>\n";

			}
			
			$strHtmlOutput .= '</select>';
			
		} else {
		//
		}
		
		$rs->Close();
		
		print $strHtmlOutput;
		
	} else {
	//
		print "rs fail";
	}
	
	$cnn->Close();
	
} else {
//
	print "fail";
}

?>